package org.cangkuguanli.wangruiqi_bookstore.controller;

import org.cangkuguanli.wangruiqi_bookstore.bean.User;
import org.cangkuguanli.wangruiqi_bookstore.mapper.UserMapper;

import org.cangkuguanli.wangruiqi_bookstore.util.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserContrller {
    @Resource
    private UserMapper userMapper;

    @RequestMapping("/login")
    public JsonResult login(User user){ //参数
        User  u= userMapper.login(user);
        if(u == null){
            //登录失败
            JsonResult result = new JsonResult(false,404,null,"账号或密码错误");
            return result;
        }else {
            //登陆成功 给前端传送用户信息
            JsonResult result = new JsonResult(true,200,u.getId(),"");
            //保存登录信息
            return result;

        }

    }

    @RequestMapping("/add")
    public JsonResult add(User user){
        userMapper.add(user);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
}
